<!--
 * @Author: hucc
 * @Date: 2021-10-14 16:46:13
 * @LastEditors: hucc
 * @LastEditTime: 2021-10-14 19:56:15
 * @Description: 
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/vue.js"></script>
    <script src="../js/vuex.js"></script>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <script src="../js/axios.js"></script>
</head>

<body>
    <div id="app">
        <el-table :data="categories" style="width:100%">
            <el-table-column type='index' label='序号'></el-table-column>
            <el-table-column prop="id" label='编号'></el-table-column>
            <el-table-column prop='name' label='栏目名称'></el-table-column>
            <el-table-column prop='description' label='栏目描述'></el-table-column>
            <!-- <el-table-column prop='no' label='序号'></el-table-column> -->
            <el-table-column prop='parentId' label='所属栏目'></el-table-column>
            <el-table-column label='操作'>
                <template v-slot="scope">
                  <el-button @click='deleteHandler(scope.row.id)' type='text'>删除</el-button>
                  <el-button @click='editHandler(scope.row)' type='text'>修改</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
    <script>
        let store = new Vuex.Store({
            state: {
                categories: []
            },
            mutations: {
                SET_CATEGORIES(state, payload) {
                    state.categories = payload
                }
            },
            actions: {
                async findAllCategories({
                    commit
                }) {
                    let res = await axios.get('http://39.103.202.53:8888/index/category/findAll')
                    commit('SET_CATEGORIES', res.data.data);
                    // console.log(res);
                }
            }
        })
        let {
            mapState,
            mapActions,
            mapMutations
        } = Vuex
        new Vue({
            el: '#app',
            data: {},
            methods: {
                ...mapActions(['findAllCategories']),
                //删除按钮处理程序
                deleteHandler(id) {
                    console.log(id);
                },
                //修改按钮处理程序
                editHandler(row) {
                    console.log(row);
                }
            },
            computed: {
                ...mapState(['categories']),

            },
            created() {
                this.findAllCategories()
            },
            store
        })
    </script>
</body>

</html>